package sys.tests.logic;

import sys.message.*;
import sys.transport.*;
import sys.database.*;

public class Test3
{
    public static void startTest(String mailServer, String sysaAddress, String DBHost, String DBName, String user, String pass)
    { 
        System.out.println("-------------------------------------------------------------");
        System.out.println("Test3 : User is silent");
        System.out.println("-------------------------------------------------------------");

        DBWrapper dbw = new DBWrapper(DBHost, DBName, user, pass);
        dbw.connect();
        dbw.delete("Request", "ID = 0");
        dbw.disconnect();

        UniMessage mes = null; 
        try
        {
            // Новый запрос к системе B
            mes = new JSONMessage(sysaAddress, "systemb@localhost.localdomain", "LOGIC TEST 1");
            mes.put("Type", "newRequest");
            mes.put("ID", 0);
            mes.put("Quantity", 10);
            mes.put("UserName", "user_1");
            mes.put("PayingSystem", "systemc@localhost.localdomain");
            new MessageSenderSMTP(mailServer).send(mes);

            Thread.sleep(2000);
            // Подтверждение от системы оплаты 
            mes = new JSONMessage("systemc@localhost.localdomain", "systemb@localhost.localdomain", "LOGIC TEST 1");
            mes.put("Type", "ackPayingSystem");
            mes.put("ackOn", 0);
            new MessageSenderSMTP(mailServer).send(mes);

            Thread.sleep(10000);
        }
        catch (Exception e)
        {
            System.out.println("Test3: Something wrong " + e.getMessage());
        }
    }
}
